/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.BorderLayout;
import java.util.Timer;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

/**
 *
 * @author vinicius
 */
public class TelaTrens extends javax.swing.JFrame {

    PainelCentral panel = 
            new PainelCentral();
    

    public PainelCentral pegap() {
           return panel;
       }

    Timer velocidade = new Timer();
        
    /**
     * Creates new form TelaTrens
     */
    public TelaTrens() {
        initComponents();
        jPanel1.add(panel, BorderLayout.CENTER);
        long o = 10000;
        velocidade.schedule(pegap().new Move(), 0, o);
        this.minhaVeloc.setMinorTickSpacing(5);
        this.minhaVeloc.setMajorTickSpacing(10);
        this.minhaVeloc.setPaintTicks(true);
        this.minhaVeloc.setSnapToTicks(true);
    }

    
    public void alterarVelocidade(double v) {
        velocidade.cancel();
        long o;
        if(v == 0) {
            o =100000;
        } else {
            v = 5000/v;
            v = v/3.6;
            o = (long) v;
        }
        velocidade=new Timer();
        velocidade.schedule(panel.new Move(), 0, o);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        painelSuperior = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        painelInferior = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        minhaVeloc = new javax.swing.JSlider();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        botaoConectado = new javax.swing.JRadioButton();
        centroJanela = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setLayout(new java.awt.BorderLayout());

        painelSuperior.setBackground(new java.awt.Color(255, 255, 255));
        painelSuperior.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        jLabel1.setText("BEM VINDO AO TREM VIEWER");
        painelSuperior.add(jLabel1);

        jPanel1.add(painelSuperior, java.awt.BorderLayout.PAGE_START);

        painelInferior.setBackground(new java.awt.Color(255, 255, 255));
        painelInferior.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opcoes Controle do Trem", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 0, 14))); // NOI18N

        jLabel2.setText("Sua Velocidade(Km/h)");
        painelInferior.add(jLabel2);

        minhaVeloc.setPaintTicks(true);
        painelInferior.add(minhaVeloc);

        jButton1.setText("Mudar Velocidade");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        painelInferior.add(jButton1);

        jButton2.setText("Parar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        painelInferior.add(jButton2);

        botaoConectado.setText("Conectado");
        botaoConectado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoConectadoActionPerformed(evt);
            }
        });
        painelInferior.add(botaoConectado);

        jPanel1.add(painelInferior, java.awt.BorderLayout.PAGE_END);

        javax.swing.GroupLayout centroJanelaLayout = new javax.swing.GroupLayout(centroJanela);
        centroJanela.setLayout(centroJanelaLayout);
        centroJanelaLayout.setHorizontalGroup(
            centroJanelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 930, Short.MAX_VALUE)
        );
        centroJanelaLayout.setVerticalGroup(
            centroJanelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 650, Short.MAX_VALUE)
        );

        jPanel1.add(centroJanela, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        alterarVelocidade(this.minhaVeloc.getValue()*5);
        int inteiro = this.minhaVeloc.getValue()*5;
        panel.getVelocidade1().setText(inteiro+" Km/h");
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        alterarVelocidade(0);
        panel.getVelocidade1().setText("0 Km/h");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void botaoConectadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoConectadoActionPerformed
        
    }//GEN-LAST:event_botaoConectadoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaTrens.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaTrens.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaTrens.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaTrens.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaTrens tela = new TelaTrens();
                tela.setVisible(true);
                tela.setSize(1030, 710);
                //tela.setExtendedState(JFrame.MAXIMIZED_BOTH);
                tela.setResizable(false);
                tela.setLocationRelativeTo(null);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton botaoConectado;
    private javax.swing.JPanel centroJanela;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSlider minhaVeloc;
    private javax.swing.JPanel painelInferior;
    private javax.swing.JPanel painelSuperior;
    // End of variables declaration//GEN-END:variables
}
